package com.xioaye.cs.basic;




import java.util.*;

public class Main3 {

    public static void main(String[] args) {

        int[] m = {4,2,6,300};
        int[] n ={5,3,8,7} ;
        int k = 15;

        // 实际需要计算最大的金额差值

        List<Product> products = new ArrayList<>();

        int[] diff = new int[m.length];

        for (int i = 0; i < m.length; i++) {
            diff[i] = n[i]- m[i];
            Product product = new Product();
                product.setIndex(i+1);
                product.setMaxPro(diff[i]);
                product.setUsed(false);

                products.add(product);
        }

        // todo  排序，冒泡法 ，加快速度而已
//        boolean[] used = new boolean[m.length];


        int sum = k;

        // 购买过程,找出最大利润的产品，
        // 把当前的利润添加到最终金额里面

        // 1,获取最大利润的产品

        Product product = getProduct(products);

       while  ( product.index!=0){
            sum = sum + product.maxPro;
            // 设置这个已经
            product.setUsed(true);
          product = getProduct(products);
       }

        System.out.println(sum);

    }

    private static Product getProduct(List<Product> products) {
        Product product = new Product();

        for (Product product1 : products) {
            if (product1.maxPro > product.maxPro && !product1.isUsed()){
                product = product1;
            }
        }
        return product;
    }


}


class  Product{

    int index; // 索引
    int maxPro ; // 最大利润

    boolean used = false;

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getMaxPro() {
        return maxPro;
    }

    public void setMaxPro(int maxPro) {
        this.maxPro = maxPro;
    }

    public boolean isUsed() {
        return used;
    }

    public void setUsed(boolean used) {
        this.used = used;
    }
}
